<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>商品列表</title>
</head>
<body>
	<jsp:include page="inc.jsp"></jsp:include>
	
	<table style="margin-top:10px" width="999" align="center" cellpadding="0" cellspacing="0" class="thin-border">
		<tr>
			<td>商品图片</td><td>商品名称</td><td>商品价格</td><td>商品库存</td><td>商品状态</td><td>操作</td>
		</tr>
		<c:forEach var="p" items="${products.datas }">
			<tr>
				<td><img  src="<%=request.getContextPath()%>/img/${p.image}" width="130" height="130"></td>
				<td><a href="product.do?method=show&id=${p.id}">${p.name }</a></td>
				<td>${p.price }</td>
				<td>
				<!-- 管理员才能显示增加库存 -->
				${p.stock }
				<c:if test="${not empty loginUser and loginUser.type eq 1 }">
				<a href="product.do?method=addStockInput&id=${p.id }">增加库存</a>
				</c:if>
				</td>
				<td><c:if test="${p.status eq 1}">可购买</c:if>
				<c:if test="${p.status eq -1}"><span style="text-decoration:line-through;color:#832">已下架</span></c:if>
				<!-- 管理员才能显示变更 -->
				<c:if test="${not empty loginUser and loginUser.type eq 1 }">
					<a href="product.do?method=changeStatus&id=${p.id}">变更</a>
				</c:if>
				</td>
				<td>
				<!-- 管理员才能显示删除和修改 -->
				<c:if test="${not empty loginUser and loginUser.type eq 1 }">
				<a href="product.do?method=updateInput&id=${p.id }">修改</a> 
				<a href="product.do?method=delete&id=${p.id}">删除</a>
				</c:if>
				<!-- 状态上架才能购买 -->
				<c:if test="${p.status eq 1 }">
				<a href="orders.do?method=addToCart&id=${p.id}">加入购物车</a>
				</c:if>
				&nbsp;
				</td>
			</tr>
		</c:forEach>
		<!-- 分页的引入 -->
		<tr>
			<td colspan="6">
				<jsp:include page="/inc/pager.jsp">
					<jsp:param value="${products.totalRecord }" name="items"/>
					<jsp:param value="product.do" name="url"/>
					<jsp:param value="method,name,cid,status" name="params"/>
				</jsp:include>
			</td>
		</tr>
		
	</table>

</body>
</html>